package org.xxforest.game.notsing.common;

public enum Dir {

	left ,
	leftUp,
	up,
	rightUp,
	right,
	rightDown,
	down,
	leftDown,;

	public static int length() {
		return Dir.values().length;
	}

	public static Dir getByDegree(float degree) {
		if(between(degree,90+22.5f,90-22.5f)){
			return up ;
		}else if(between(degree,-90+22.5f,-90-22.5f)){
			return down ;
		}else if(between(degree,0+22.5f,0-22.5f)){
			return right ;
		}else if(between(degree,180,180-22.5f) || between(degree,-180,-180+22.5f)){
			return left ;
		}else if(between(degree,45+22.5f,45-22.5f)){
			return rightUp ;
		}else if(between(degree,-45+22.5f,-45-22.5f)){
			return rightDown ;
		}else if(between(degree,-135+22.5f,-135-22.5f)){
			return leftDown ;
		}else if(between(degree,135+22.5f,135-22.5f)){
			return leftUp ;
		}
		return up ;
	}

	private static boolean between(float degree ,float d, float e) {
		return (d - degree ) * (e - degree ) <= 0  ;
	}
}
